#pragma once

#include  "iostream"
#include  "vector"
#include  "stack"
#include  "unordered_map"
#include   "queue"

using namespace std;

/*
 *
 * 输入一个正整数 target ，输出所有和为 target 的连续正整数序列（至少含有两个数）。

序列内的数字由小到大排列，不同序列按照首个数字从小到大排列。



示例 1：

输入：target = 9
输出：[[2,3,4],[4,5]]
示例 2：

输入：target = 15
输出：[[1,2,3,4,5],[4,5,6],[7,8]]
 * */


vector<vector<int>> findContinuousSequence(int target) {
    vector<vector<int>> res;
    vector<int> temp;

    int mid = target / 2 + 1;
    int low = 1;
    int high = 2;
    int sum = 3;
    while (low <= high && high <= mid) {
        if (sum == target && high - low == 0)
            break;

        if (sum == target) {
            temp.clear();
            for (int i = low; i <= high; ++i) {
                temp.push_back(i);
            }
            res.push_back(temp);
            sum -= low;
            low++;
        } else if (sum < target) {
            high++;
            sum += high;
        } else if (sum > target) {
            sum -= low;
            low++;
        }


    }

    return res;
}